package cn.yuhh.serviec.impl;

import cn.yuhh.dao.TypeDao;
import cn.yuhh.entity.Type;
import cn.yuhh.serviec.ITypeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeService implements ITypeService {

    @Autowired
    private TypeDao typeDao;


    @Override
    public Page<Type> listType(Pageable pageable) {
        return typeDao.findAll(pageable);
    }

    @Override
    public Type findById(Long id) {
        return typeDao.getOne(id);
    }

    @Override
    public void updateTypeById(Long id, Type type) {
        Type t = typeDao.getOne(id);
        BeanUtils.copyProperties(type, t);
        typeDao.save(t);
    }

    @Override
    public Type findByName(String name) {
        return typeDao.findByName(name);
    }

    @Override
    public Type save(Type type) {
        return typeDao.save(type);
    }

    @Override
    public void deleteById(Long id) {
        typeDao.deleteById(id);
    }

    @Override
    public List<Type> listType() {
        return typeDao.findAll();
    }
}
